<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <div id="app">
        <ul>
            <!-- item:表示数组的每一项数据 -->
            <!-- index:表示数组的下标 -->
            <li v-for="(item,index) in movies" v-on:click="changeColor(item,index)" :style="{color:item.flag}">
                {{item.name}}</li>
        </ul>
    </div>

    <script src="./vue.js"></script>
    <script>
        let app = new Vue({
            el: "#app",
            data: {
                movies: [{
                        name: "流浪地球",
                        flag: ""
                    },
                    {
                        name: "封神",
                        flag: ""
                    },
                    {
                        name: "人在囧途",
                        flag: ""
                    },
                    {
                        name: "泰囧",
                        flag: ""
                    },
                ]

            },
            methods: {
                changeColor(item, index) {
                    // 先全部把所有对象里面的flag值改为false
                    this.movies.forEach(element => {
                        element.flag = ""
                    });

                    // 当前点击的电影对象的flag改为true
                    if (item.flag) {
                        item.flag = "";
                    } else {
                        item.flag = "red";

                    }

                }
            }
        })
    </script>

</body>

</html>